import service from "../services/request";
import { SWZDefaultDataAll } from "@/utils/swz";
import { merge as LodashMerge } from "lodash";
// 是否是 mock 数据
const isMockData = window.SUPER_GIS_SPACE.isMockData
//本地文件路径 前半部分
const staticFilePath = '/staticData/'
function ParseTime(time, cFormat) {
  if (arguments.length === 0 || !time) {
    return null
  }
  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if (typeof time === 'string') {
      if (/^[0-9]+$/.test(time)) {
        time = parseInt(time)
      } else {
        // support safari
        // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
        time = time.replace(new RegExp(/-/gm), '/')
      }
    }

    if (typeof time === 'number' && time.toString().length === 10) {
      time = time * 1000
    }
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
    const value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') {
      return ['日', '一', '二', '三', '四', '五', '六'][value]
    }
    return value.toString().padStart(2, '0')
  })
  return time_str
}
const Api = {
  // 通用接口,传递参数不同,返回结果不同 ok
  getDataByConfigApi(data) {
    // if(data.cfgName !== '数字孪生-各单位航标数量统计') {
    //   return
    // }
    return new Promise(resolve => {
      service({
        url: 'api/blade-auth/ext/api/api/oauth/token',
        method: 'POST',
        data: {
          tenantId: '999999',
          clientId: 'E22FD5F1C4BFAFC5B0AA942E8D8C897E',
          clientSecret: 'B286A52679279168FAE6865AD39AC976',
          grantType: 'api'
        },
        headers: {
          Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
        }
      }).then(res => {
        const token = res.data.refresh_token
        service({
          url: 'api/datacenter/dataapiCfg/dc/getDataByConfigApi',
          method: 'POST',
          data,
          headers: {
            'Blade-Auth': token
          }
        }).then(res_ => {
          resolve(res_)
        })
      })
    })
    // return service({
    //   url: "api/datacenter/dataapiCfg/dc/getDataByConfigApi",
    //   method: "POST",
    //   data,
    // });
  },
  //航标数量统计 ok
  getDataByConfigApiHBCount() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: staticFilePath + '数字孪生-各单位航标数量统计.json',
        method: 'GET',
      }).then(res => {
        resolve(res)
      })
    })
  },
  //实装航标数量统计 ok
  getDataByConfigApiHBshiCount() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: staticFilePath + '数字孪生-各单位实装数字航标数量统计.JSON',
        method: 'GET',
      }).then(res => {
        resolve(res)
      })
    })
  },
  //电子航道图中心-尺度预警数据 ok
  getDataByConfigApiHDTCD() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: staticFilePath + '电子航道图中心-尺度预警数据.json',
        method: 'GET',
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 航标告警 ok
  getNavEmergency(data) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + '航标告警-hbbjxx.json',
        method: 'GET',
      })
    } else {
      return service({
        url: 'api/fw/hb/hbbjxx/',
        method: 'POST',
        data,
        headers: { 'Content-Type': 'multipart/form-data' }
      })
    }
  },
  // 获取天气数据 ok
  getWeatherDataOfArea() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '数字孪生-示范段天气数据.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-示范段内天气数据'
      })
    }

  },
  // 新接口 等待接入 获取长江全线气象预警 ok
  getPredictWeatherDataOfYangz() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '数字孪生-长江全线气象预警.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-长江全线气象预警',
        map: {
          pub_date: dayjs(new Date().getTime() - 86400000).format('YYYY-MM-DD')
        }
      })
    }
  },
  // 获取船舶的速度热力图 ok
  getSpeedMapOfShip() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '船舶速度热力图.json',
          method: 'GET',
        }).then(res => {
          const finalArr = []
          for (let i = 0; i < res.data.dimPointDictVOS.length; i++) {
            const curr = res.data.dimPointDictVOS[i]
            for (let j = 0; j < curr.length; j++) {
              finalArr.push({
                lng: curr[j].lng,
                lat: curr[j].lat,
                speed: curr[j].speed,
                speedColor: curr[j].speedColor
              })
            }
          }
          resolve(finalArr)
        })
      })
    } else {
      return new Promise(resolve => {
        service({
          url: 'api/blade-auth/ext/api/api/oauth/token',
          method: 'POST',
          data: {
            tenantId: '999999',
            clientId: 'B6EDE911B5039C8A9EA5F5789E39EB8D',
            clientSecret: '0D515A71EAA3A764C9443A90BC2F1723',
            grantType: 'api'
          },
          headers: {
            Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
          }
        }).then(res => {
          const access_token = res.data.access_token
          service({
            url: 'api/datacenter/dataapiCfg/dc/getDataByLocalApi',
            method: 'POST',
            data: { cfgName: '船舶速度' },
            headers: {
              'Blade-Auth': access_token
            }
          }).then(res => {
            const finalArr = []
            for (let i = 0; i < res.data.dimPointDictVOS.length; i++) {
              const curr = res.data.dimPointDictVOS[i]
              for (let j = 0; j < curr.length; j++) {
                finalArr.push({
                  lng: curr[j].lng,
                  lat: curr[j].lat,
                  speed: curr[j].speed,
                  speedColor: curr[j].speedColor
                })
              }
            }
            resolve(finalArr)
          })
        })
      })
    }
  },
  // 船舶数量热力图  ok
  getHotMapData() {
    if (isMockData) {
      // mock 数据
      return new Promise(resolve => {
        service({
          // 相对路径
          // baseURL: window.location.pathname,
          // url: './files/data/heat-map.json',
          // method: 'GET'
          baseURL: window.location.pathname,
          url: staticFilePath + '船舶数量热力图.json',
          method: 'GET',
        }).then(res => {
          console.log(res, 'res船舶热力数量图');
          const finalArr = []
          for (let i = 0; i < res.data.dimPointDictVOS.length; i++) {
            const curr = res.data.dimPointDictVOS[i]
            for (let j = 0; j < curr.length; j++) {
              finalArr.push({
                lng: curr[j].lng,
                lat: curr[j].lat,
                number: curr[j].number,
                color: curr[j].numberColor
              })
            }
          }
          resolve(finalArr)
        })
      })
    } else {
      // 真实动态数据
      return new Promise(resolve => {
        service({
          url: 'api/blade-auth/ext/api/api/oauth/token',
          method: 'POST',
          data: {
            tenantId: '999999',
            clientId: 'B6EDE911B5039C8A9EA5F5789E39EB8D',
            clientSecret: '0D515A71EAA3A764C9443A90BC2F1723',
            grantType: 'api'
          },
          headers: {
            Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
          }
        }).then(res => {
          const access_token = res.data.access_token
          service({
            url: 'api/datacenter/dataapiCfg/dc/getDataByLocalApi',
            method: 'POST',
            data: { cfgName: '船舶数量' },
            headers: {
              'Blade-Auth': access_token
            }
          }).then(res => {
            const finalArr = []
            for (let i = 0; i < res.data.dimPointDictVOS.length; i++) {
              const curr = res.data.dimPointDictVOS[i]
              for (let j = 0; j < curr.length; j++) {
                finalArr.push({
                  lng: curr[j].lng,
                  lat: curr[j].lat,
                  number: curr[j].number,
                  color: curr[j].numberColor
                })
              }
            }
            resolve(finalArr)
          })
        })
      })
    }
  },
  //  获取航路的面数据 本地 JSON ok
  getGeoJSONDatdaOfHanglu() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/航路.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 7 天水位预测 获取登陆的Token
  getTokenOfDeptwaveAuth() {
    return new Promise((resolve, reject) => {
      service({
        url: 'api/v1/deptwave-auth/login/login',
        method: 'POST',
        data: {
          username: 'root',
          password: 'Root@2023'
        }
      }).then(res => {
        resolve(res.content || '')
      })
    })
  },
  // 获取 7 天水位数据 预测水位  接口已经通过，数据为 [] ok
  async get7WaterForecastAnalysisListWhole() {
    if (isMockData) {
      //  预测假数据
      return new Promise(resolve => {
        service({
          // 相对路径
          baseURL: window.location.pathname,
          url: staticFilePath + '7 天水位数据.json',
          method: 'GET'
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      const token = await Api.getTokenOfDeptwaveAuth()
      return new Promise(resolve => {
        service({
          url:
            'api/v1/deptwave-system/bas-7-water-forecast-result/get7WaterForecastAnalysisListWhole',
          method: 'GET',
          params: {
            date: ParseTime(new Date(), '{y}-{m}-{d}') + ' 08:00:00'
          },
          headers: {
            Authorization: token.token
          }
        }).then(res => {
          resolve(res)
        })
      })
    }
  },
  // 过去 7 天的数据 ok
  async get7WaterPassAnalysisListWhole(data) {
    if (isMockData) {
      return new Promise(resolve => {
        // resolve(Pass7Data)
        service({
          // 相对路径
          baseURL: window.location.pathname,
          url: staticFilePath + '水位动态监测数据-过去7天.json',
          method: 'GET'
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      const res = await Api.getDataByConfigApi(data)
      return new Promise(resolve => {
        resolve(res)
      })
    }
  },
  // L1 级别页面社会船统计 ok
  getCountOfShipInSocial() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '在航船舶.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({ cfgName: '在航船舶', map: { name: '' } })
    }
  },
  // 获取河流的场数据
  getWaterFieldData() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/files/data/waterFieldData.json',
        method: 'POST'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取河流的场数据
  getWaterFieldData2() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/files/data/流场0612.json',
        method: 'get'
      }).then(res => {
        resolve(res)
      })
    })
  },
  /**
   * 获取断面信息字典表
   * @returns 
   */
  getDuanMianDic(token) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET'
      });
    } else {

      return service({

        url: "api/datacenter/dataapiCfg/dc/getDataByConfigApi",

        method: "POST",

        headers: {
          'Blade-Auth': token
        },
        data: {

          cfgName: 'api_断面字典表'

        },

      });

    }
  },
  getDuanMianList(token, time) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET'
      });

    } else {

      return service({

        url: "api/datacenter/dataapiCfg/dc/getDataByConfigApi",

        method: "POST",
        headers: {
          'Blade-Auth': token
        },
        data: {
          cfgName: 'api_断面流量数据',
          map: {
            "time_a": time.startTime,
            "time_b": time.endTime
          }
        },

      });

    }
  },
  getDuanMianInfoBySectionId(sectionId, time) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET'
      });

    } else {

      return service({

        url: "api/datacenter/dataapiCfg/dc/getDataByConfigApi",

        method: "POST",

        data: {

          cfgName: '数字孪生-查询单个断面',

          map: {

            "time_a": time.startTime,

            "time_b": time.endTime,

            "section_id": sectionId

          }

        },

      });
    }
  },
  // 获取动态航路
  getHL() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET'
      });
    } else {
      return service({
        url: "api/zt/intf/hlInfo",
        method: "GET",
      });
    }

  },
  getStaticHLLine(idx) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET'
      });
    } else {
      return service({
        url: "http://172.18.10.104:8090/iserver/services/data-HDT_SW_TQ/rest/data/feature/0-56-" + idx + ".json?hasGeometry=true",
        method: "GET",
      });
    }
  },
  // 根据 mmsi 获取船只的信息
  getShipDataByMMSI({ mmsi }) {
    return service({
      url: 'api/ship-dynamic-data/info/' + mmsi,
      method: 'POST'
    })
  },
  // 获取示范段内的航标告警数据
  getWarnDataOfHangBiao() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '数字孪生-示范段内航标告警数据.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-示范段内航标告警数据'
      })
    }
  },
  // 获取洗舱站的数据 ok
  getDataOfXiCang() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/xicang.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  //  获取武汉段的洗舱站数据
  getDataOfXiCangAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/洗舱站-武汉段.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取加油站的数据 ok
  getDataOfJiaYouZhan() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/加油站.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  //  获取武汉段的加油站数据
  getDataOfJiaYouZhanAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/加油站-武汉段.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取岸电的数据 ok
  getDataOfAnDian() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/andian.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 武汉段的岸电数据
  getDataOfAndianAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/岸电数据武汉段.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取服务区的数据 ok
  getDataOfFuWuQu() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/服务区.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  //  获取武汉段水上服务区的数据
  getDataOfFuWuQuAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/服务区-武汉段.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取污染物的数据 ok
  getDataOfWuRanWu() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/污染物新.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取武汉污染物的数据
  getDataOfWuRanWuAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/武汉污染物.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取武汉地标建筑物的数据
  getDataOfLandMarkAtWH() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/长江沿岸武汉段地标.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取整治建筑物的数据 ok
  getZhengZhiBuilding() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/整治建筑物.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取应急管理机构的数据 ok
  getYingJiGuanLi() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/应急管理机构.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取地质灾害数据 ok
  getDiZhiZaiHai() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/地质灾害数据.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取水域范围数据 ok
  getAreaOfWater() {
    // http://172.18.10.104:8090/iserver/services/data-WorkSpace-2/rest/data/datasources/长江干线预览/datasets/干线_一级
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        // url: "./files/data/L1/长江北斗网一级二级水域范围.json",
        url: '/files/data/L1/waterAreaFromServer.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取气象站的数据 ok
  geWeatherStationtDict() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/L1/气象站字典表转化.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // L1 级别获取航道尺度接口
  getDimenOfChannelData() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/files/data/fake451.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // L1级别获取水位接口 ok
  getDimenOfWaterData() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/files/data/fake402.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取航道尺度的预警信息
  getWarnDataOfChannel() {
    if (isMockData) {
      return new Promise(resolve => {
        resolve([])
      })
    } else {
      return new Promise((resolve, reject) => {
        const data = {
          plat_key: window.SUPER_GIS_SPACE.plat_key,
          page_size: 180000,
          params: JSON.stringify({
            hd_id: 'WH_c693a782084040968cc90502607d30d0'
          })
        }
        service({
          url: 'api/fw/hd/hdzybcd/',
          method: 'POST',
          data,
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }).then(ycRes => {
          const results = ycRes.d?.results
          const obj = {}
          if (results && results.length > 0) {
            results.forEach(o => {
              if (o.gxsj) {
                obj[o.hd_id] ??= o
                if (obj[o.hd_id] == o.hd_id) {
                  const time = new Date(obj[o.hd_id].gxsj).getTime()
                  const time2 = new Date(o.gxsj).getTime()
                  if (time2 > time) {
                    obj[o.hd_id] = o
                  }
                }
              }
            })
          } else {
            resolve([])
            return
          }

          service({
            url: 'api/fw/hd/hdsccd/',
            method: 'POST',
            data,
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          }).then(res => {
            const results2 = res.d?.results || []
            const ress = []
            const P = 0.3
            const time = new Date(new Date().toLocaleDateString()).getTime()
            if (results2 && results2.length > 0) {
              results2.forEach(e => {
                const zqss1 = e.zqss
                const zqss2 = obj[e.hd_id]?.hdss
                const time2 = new Date(e.cssj).getTime()
                if (obj[e.hd_id] && zqss2 && zqss1 - zqss2 <= P && time2 > time) {
                  const n = LodashMerge({}, obj[e.hd_id], e)
                  try {
                    n.qqwz = JSON.parse(n.qqwz)
                    n.showPOI = true
                  } catch {
                    n.qqwz = e.qqwz
                  }
                  ress.push(n)
                }
              })
              resolve(ress)
            }
          })
        })
      })
    }

  },
  // 数字孪生-公共突发事件接口数据 ok

  // ZBJD ZBWD
  // SJBT 事件标题
  // SJGK 时间概况
  // LXDH LXR 联系电话 联系人
  //
  getDataOfPublicEvent() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + '数字孪生-公共突发事件接口数据.json',
        method: 'GET',
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-公共突发事件接口数据'
      })
    }

  },
  // 获取断面流量的字典表
  getDictDataOfDuanMianLiuliang() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'api_断面字典表.json',
        method: 'GET',
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: 'api_断面字典表'
      })
    }

  },
  // 获取断面流量 ok
  async getDataOfDuanMianLiuliang() {
    if (isMockData) {
      const resOfDict = await Api.getDictDataOfDuanMianLiuliang({
        cfgName: 'api_断面字典表'
      })
      console.log(resOfDict, 'resOfDict');
      if (!resOfDict.success) {
        return
      }
      if (
        !resOfDict.data ||
        !resOfDict.data.data ||
        !resOfDict.data.data.length
      ) {
        return
      }
      const DictData = {}
      for (let i = 0; i < resOfDict.data.data.length; i++) {
        const section = resOfDict.data.data[i]
        if (section.section_id == undefined) {
          continue
        }
        DictData[section.section_id] = section
      }
      const finalArr = []
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + 'api_断面流量数据.json',
          method: 'GET',
        }).then(resOfLiuliang => {
          console.log(resOfLiuliang, 'resOfLiuliang');
          // resolve(res)
          if (!resOfLiuliang.success) {
            return
          }
          if (
            !resOfLiuliang.data ||
            !resOfLiuliang.data.data ||
            !resOfLiuliang.data.data.length
          ) {
            return
          }

          const MapOfUpDown = {}

          const resOfLiuliangFilterd = resOfLiuliang.data.data.filter(v => {
            return v.SECTIONID && DictData[v.SECTIONID]
          })
          function tempFunc(directionUpTag, section) {
            if (directionUpTag) {
              MapOfUpDown[section.SECTIONID].SHIPNUMBER_UP = section.SHIPNUMBER
            } else {
              MapOfUpDown[section.SECTIONID].SHIPNUMBER_DOWN = section.SHIPNUMBER
            }
            MapOfUpDown[section.SECTIONID].REGIONDATA = DictData[section.SECTIONID]
            MapOfUpDown[section.SECTIONID].RIQI = section.RIQI
          }

          for (let j = 0; j < resOfLiuliangFilterd.length; j++) {
            const section = resOfLiuliangFilterd[j]
            // 1 为上行 2 为下行
            const directionUpTag = section.DIRECTION === '1'
            if (MapOfUpDown[section.SECTIONID]) {
              tempFunc(directionUpTag, section)
            } else {
              MapOfUpDown[section.SECTIONID] = {}
              tempFunc(directionUpTag, section)
            }
          }

          for (const key in MapOfUpDown) {
            const item = MapOfUpDown[key]
            item.SECTIONID = key
            finalArr.push(item)
          }
          // console.log(finalArr,'finalArr');
          console.log(Date.now(), 'finalArr');
          resolve(finalArr)
        })

      })

    } else {
      const resOfDict = await Api.getDictDataOfDuanMianLiuliang({
        cfgName: 'api_断面字典表'
      })
      if (!resOfDict.success) {
        return
      }
      if (
        !resOfDict.data ||
        !resOfDict.data.data ||
        !resOfDict.data.data.length
      ) {
        return
      }
      const DictData = {}
      for (let i = 0; i < resOfDict.data.data.length; i++) {
        const section = resOfDict.data.data[i]
        if (section.section_id == undefined) {
          continue
        }
        DictData[section.section_id] = section
      }
      const date = dayjs(new Date().getTime() - 86400000).format('YYYY-MM-DD')
      const resOfLiuliang = await Api.getDataByConfigApi({
        cfgName: 'api_断面流量数据',
        map: {
          time_a: date,
          time_b: date
        }
      })
      if (!resOfLiuliang.success) {
        return
      }
      if (
        !resOfLiuliang.data ||
        !resOfLiuliang.data.data ||
        !resOfLiuliang.data.data.length
      ) {
        return
      }

      const MapOfUpDown = {}

      const resOfLiuliangFilterd = resOfLiuliang.data.data.filter(v => {
        return v.SECTIONID && DictData[v.SECTIONID]
      })

      function tempFunc(directionUpTag, section) {
        if (directionUpTag) {
          MapOfUpDown[section.SECTIONID].SHIPNUMBER_UP = section.SHIPNUMBER
        } else {
          MapOfUpDown[section.SECTIONID].SHIPNUMBER_DOWN = section.SHIPNUMBER
        }
        MapOfUpDown[section.SECTIONID].REGIONDATA = DictData[section.SECTIONID]
        MapOfUpDown[section.SECTIONID].RIQI = section.RIQI
      }

      for (let j = 0; j < resOfLiuliangFilterd.length; j++) {
        const section = resOfLiuliangFilterd[j]
        // 1 为上行 2 为下行
        const directionUpTag = section.DIRECTION === '1'
        if (MapOfUpDown[section.SECTIONID]) {
          tempFunc(directionUpTag, section)
        } else {
          MapOfUpDown[section.SECTIONID] = {}
          tempFunc(directionUpTag, section)
        }
      }
      const finalArr = []
      for (const key in MapOfUpDown) {
        const item = MapOfUpDown[key]
        item.SECTIONID = key
        finalArr.push(item)
      }
      return new Promise(resolve => {
        resolve(finalArr)
      })
    }

  },
  // 获取航道通行状态的接口 ok
  async getDataOfChannelOpenStatus() {
    const resData = await Api.getDataByConfigApi({
      cfgName: '数字孪生-航道通行状态'
    });
    return new Promise(resolve => {
      resolve(resData)
    })
  },
  // 获取航道设备状态的接口 ok
  async getDataOfChannelEquipStatus() {
    const resData = await Api.getDataByConfigApi({
      cfgName: '数字孪生-航道设施状态'
    });
    return new Promise(resolve => {
      resolve(resData)
    })
  },
  // 获取示范段内水位动态数据
  getDynamicDataOfWaterLevel() {
    if (isMockData) {
      return new Promise(resolve => {
        resolve([])
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-示范段内水位动态数据'
      })
    }
  },
  // 获取工作船的统计 适用于 L1 级别 ok
  // 该接口当前异常 2024年4月25日09:11:55
  getDataOfWorkingShip() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-infotongji.json',
        method: 'GET',
      })
    } else {
      return service({
        url: 'api/ship-info/tongji',
        method: 'POST'
      })
    }

  },
  /**
   * 机务船数据
    "lon": "经度",
    "lat": "纬度",
    "time": "时间戳精确到秒",
    "run": "船舶运行状态 0 表示停泊， 1 表示运行",
    "hjx": "航迹向",
    "syyl": "剩余油量",
    "fid": "船舶id",
    "fshipname": "船只名称",
    "fhs": "航速",
    "fszc": "所在处",
    "fmzcs": "满载吃水",
    "fxk": "宽度",
    "fxs": "深度",
    "fzgl": "总功率",
    "fshiptypeid": 船舶类型,
    "fkzcs": "空载吃水",
    "finfoid": 0,
    "fzc": "长度",
    "fshipcx": "船型",
    "fmodifydate": "",
    "fccn": "出厂年度"
  */
  getDataOfMaintShip() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-infopageAll.json',
        method: 'GET',
      })
    } else {
      return service({
        url: 'api/ship-info/pageAll',
        method: 'POST',
        data: {
          pageNum: 1,
          pageSize: 9999
        }
      })
    }

  },
  // 获取全线当月航标碰撞top20数据 ok
  getDataOfTop20Crashed() {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '数字孪生-全线当月航标碰撞top20.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-全线当月航标碰撞top20'
      })
    }

  },
  // 获取各个处级单位的航行标志、信号标志、专用标志、警示标志的接口 ok
  getDataOf4TagsAtBureau() {
    // 考虑各个航道局的顺序，
    // 页面上是按照地理角度从左到右依次是宜昌到上海
    // 接口返回不会按照这个顺序
    return new Promise(resolve => {
      const arrs = [
        {
          name: '航行标志',
          data: [],
          color: '#34c994'
        },
        {
          name: '信号标志',
          data: [],
          color: '#ffb50a'
        },
        {
          name: '专用标志',
          data: [],
          color: '#736bf4'
        },
        {
          name: '警示标志',
          data: [],
          color: '#f8726c'
        }
      ]
      const bureausArr = {
        宜宾航道局: 0,
        泸州航道局: 0,
        重庆航道局: 0,
        涪陵航道处: 0,
        万州航道处: 0,
        宜昌航道局: 0,
        荆州航道处: 0,
        岳阳航道处: 0,
        武汉航道局: 0,
        九江航道处: 0,
        芜湖航道处: 0,
        南京航道局: 0,
        镇江航道处: 0,
        上海航道处: 0
      }
      if (isMockData) {
        console.log('航标设标数11111111');
        Promise.all([
          new Promise(resolve => {
            service({
              baseURL: window.location.pathname,
              url: staticFilePath + '数字孪生-各局处设四大类航标数量-HB_HXBZ.json',
              method: 'GET',
            }).then(res => {
              resolve(res)
            })
          }),
          new Promise(resolve => {
            service({
              baseURL: window.location.pathname,
              url: staticFilePath + '数字孪生-各局处设四大类航标数量-HB_XHBZ.json',
              method: 'GET',
            }).then(res => {
              resolve(res)
            })
          }),
          new Promise(resolve => {
            service({
              baseURL: window.location.pathname,
              url: staticFilePath + '数字孪生-各局处设四大类航标数量-HB_ZYBZ.json',
              method: 'GET',
            }).then(res => {
              resolve(res)
            })
          }),
          new Promise(resolve => {
            service({
              baseURL: window.location.pathname,
              url: staticFilePath + '数字孪生-各局处设四大类航标数量-HB_JSBZ.json',
              method: 'GET',
            }).then(res => {
              resolve(res)
            })
          }),
        ]).then(res => {
          console.log(res, '航标设标数');
          const tempArr = []
          for (let i = 0; i < res.length; i++) {
            const item = res[i]
            if (!item || !item.data || !item.data.data) {
              tempArr.push(JSON.parse(JSON.stringify(bureausArr)))
              continue
            }
            tempArr.push(item.data.data[0])
          }

          for (let j = 0; j < tempArr.length; j++) {
            const item = tempArr[j]
            delete item.Total
            for (const key in bureausArr) {
              arrs[j].data.push({
                name: key,
                value: item[key]
              })
            }
          }
          resolve(arrs)
        })
      } else {
        Promise.all([
          Api.getDataByConfigApi({
            cfgName: '数字孪生-各局处设四大类航标数量',
            map: { hbdl: 'HB_HXBZ' }
          }),
          Api.getDataByConfigApi({
            cfgName: '数字孪生-各局处设四大类航标数量',
            map: { hbdl: 'HB_XHBZ' }
          }),
          Api.getDataByConfigApi({
            cfgName: '数字孪生-各局处设四大类航标数量',
            map: { hbdl: 'HB_ZYBZ' }
          }),
          Api.getDataByConfigApi({
            cfgName: '数字孪生-各局处设四大类航标数量',
            map: { hbdl: 'HB_JSBZ' }
          })
        ]).then(res => {
          const tempArr = []
          for (let i = 0; i < res.length; i++) {
            const item = res[i]
            if (!item || !item.data || !item.data.data) {
              tempArr.push(JSON.parse(JSON.stringify(bureausArr)))
              continue
            }
            tempArr.push(item.data.data[0])
          }

          for (let j = 0; j < tempArr.length; j++) {
            const item = tempArr[j]
            delete item.Total
            for (const key in bureausArr) {
              arrs[j].data.push({
                name: key,
                value: item[key]
              })
            }
          }
          resolve(arrs)
        })
      }

    })
  },
  // AIS 动态数据
  getShipDynamicData(params) {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apiship-dynamic-datapageStatus-船舶AIS状态.json',
        method: 'GET',
      })
    } else {
      return service({
        url: 'api/ship-dynamic-data/page',
        method: 'GET',
        params
      })
    }

  },
  // AIS 静态数据
  getShipStaticData(params) {
    return service({
      url: 'api/ship-static-data/page',
      method: 'GET',
      params
    })
  },
  // 水位静态数据 ok
  getHdswz() {
    return new Promise(resolve => {
      resolve(SWZDefaultDataAll)
    })
  },
  // 全域水位信息 ok
  getAllAreaWaterLevel() {
    if (isMockData) {
      return service({
        baseURL: window.location.pathname,
        url: staticFilePath + 'apifwszszdt8ssw-全域水位信息.json',
        method: 'GET',
      })
    } else {
      const time = ParseTime(
        new Date(new Date().toLocaleDateString()).getTime() + 8 * 60 * 60000
      )
      return service({
        url: 'api/fw/sz/szdt8ssw/',
        method: 'POST',
        data: {
          plat_key:
            '657db6c7852b51ac3404e9d4449d4dde99dfacbc3fb119d6696c5ddde9b6a8f2',
          page_size: 1000,
          order: '-gxsj',
          params: JSON.stringify({ clsj: time })
        },
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      })
    }

  },
  // 航道尺度
  getHdcd() {
    return service({
      url: 'http://www.cjienc.com:4001/api/jsc/zyb/yjh/hdt',
      method: 'GET',
      plat_key:
        '684308a6a5cbda36e9eb994844f33544b8d2ec1cdeb6ca00c5f3cc1b9376370d'
    })
  },
  // 摄像头点位数据
  getVideoData() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/videos.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // UV 数据
  getFieldDataWithUV() {
    return new Promise(resolve => {
      resolve([])
    })
  },
  // 处理后的数据
  getFieldDataWithUVFilter() {
    return new Promise(resolve => {
      service({
        // 相对路径
        baseURL: window.location.pathname,
        url: '/files/data/FieldDataFromJianzhouFinal.json',
        method: 'GET'
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 新接口 获取船只的历史数据
  getHisdataOfShip(data) {
    let isMockData = true;
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + 'ais历史接口数据.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-指定范围与时间段査询历史AIS数据',
        map: data
      })
    }
  },
  // 潮汐水位接口
  // 指定潮位站过去7天潮位信息
  // 每日最高潮位(cg1)、8点水位(cw8)、最低潮位(cg2)与高潮潮时(cs1)、低潮潮时(cs2)
  getWaterLevelDataInHis({ end_time }) {
    if (isMockData) {
      return new Promise(resolve => {
        service({
          baseURL: window.location.pathname,
          url: staticFilePath + '指定潮位站过去7天潮位.json',
          method: 'GET',
        }).then(res => {
          resolve(res)
        })
      })
    } else {
      return Api.getDataByConfigApi({
        cfgName: '数字孪生-指定潮位站过去7天潮位',
        map: {
          swz_id: "NJ_402881144ffde222014ffe382dc80023",
          end_time: end_time,
        }
      })
    }
  }
}
export default Api